/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package grest.controller;

import grest.model.DataIO;
import grest.view.VistaEstadisticas;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JLabel;
import javax.swing.JTabbedPane;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;

/**
 *
 * @author Agustin
 */
public class CntrlrEstadisticas implements ChangeListener{
    VistaEstadisticas form;
    
    
    public CntrlrEstadisticas(VistaEstadisticas form){
        this.form = form;
    }
    
    @Override
    public void stateChanged(ChangeEvent e) {
        JTabbedPane sourceTabbedPane = (JTabbedPane) e.getSource();
        int index = sourceTabbedPane.getSelectedIndex();
        try {
            changePanel(index);
        } catch (SQLException ex) {
          //  Logger.getLogger(CntrlrEstadisticas.class.getName()).log(Level.SEVERE, null, ex);
            System.out.print(ex.getMessage());
        }
    }
    
    public void changePanel(Integer index) throws SQLException{
        switch(index){
        case 0: setPanelReservasClientes()  ;

        break;
        case 1: setPanelHistReservas() ;

        break;
        case 2: setProductosPedidos() ;

        break;
        case 3: setMontoTotal();

        break;
        }
    }
    
    
    public void setPanelReservasClientes(){
    }
    
    public void setPanelHistReservas() throws SQLException{
        String totales = null,concretadas = null,canceladas = null;
        String query = "Select totales,concretadas,canceladas from v_estad_reserv";
        ResultSet rs = DataIO.getResultSet(query);
        while (rs.next()){
            if (rs.getInt("totales")==0)
                totales="0";
            else totales = String.valueOf(rs.getInt("totales"));
            if (rs.getInt("concretadas")==0)
                concretadas="0";
            else concretadas = String.valueOf(rs.getInt("concretadas"));
            if (rs.getInt("canceladas")==0)
                canceladas="0";
            else 
                canceladas = String.valueOf(rs.getInt("canceladas"));
           ////////////////////////////////////////////////////////////
            ((JLabel)form.getControls("lblValorTotales")).setText(totales);
           ((JLabel)form.getControls("lblValorCanceladas")).setText(canceladas);
           ((JLabel)form.getControls("lblValorConcretadas")).setText(concretadas);
        }

    }
    
    public void setProductosPedidos(){
        
    }
    
    public void setMontoTotal(){
        
    }
}